RichText variable, how to get RTF text?

Hi all,

in order to detect OLE objects inside an object, and then replace them by a little markup, I'm trying the following code:

 

        // Concat  the NO-OLE + OLE MARKUPS
        Buffer result = create
        
        // Identifying OLE objects variables
        int oleId = 0
        string oleMarkup = ""
        
        // Loop variables
        EmbeddedOleObject embeddedOleObject
        
        RichText rtf
        Buffer buf = create
        buf += richTextWithOle(theObject."Object Text")
        for rtf in tempStringOf(buf) do {
                if (rtf.isOle) {

                        // OLE found => Build up markup
                        oleMarkup = "<oleObject id=\"" "" oleId "" "\"/>"
                        
                        // Append markup to buffer
                        result += oleMarkup

                        // Increasing the ole identifier
                        oleId += 1
                } else {
                        
                        // OLE not found => Concat to buffer ---------------------> PROBLEM: HERE I'M LOSING THE RTF FORMATTING.. How can I get the RTF text from the "RichText"  variable?? I only find the "rtf.Text" property :(
                        result += rtf.text
                }
        }

 

This is more or less working fine (buffer performance not fully tested yet, so tips are always welcome), but my problem is that when IS NOT OLE, I want to get the formatted text (RTF), and not the plain text as I'm getting with the "rtf.Text" property.

After googling and searching in the forum, I could not find any way of getting what I need, so any advice?

Best regards,

Borja.

 


Borja López - Wed Mar 25 07:42:51 EDT 2015

Re: RichText variable, how to get RTF text?
Wolfgang Uhr - Wed Mar 25 13:33:04 EDT 2015

buf += richText(theObject."Object Text") ?

Re: RichText variable, how to get RTF text?
Borja López - Thu Mar 26 04:16:00 EDT 2015

Wolfgang Uhr - Wed Mar 25 13:33:04 EDT 2015

buf += richText(theObject."Object Text") ?

This way I would get the RTF of the whole object.

However, what I want to get is the RTF of the non-OLE parts (the ELSE side in the code), together with a replacing markup for the OLE parts (the IF side), so your solution is not valid for my problem.

Regards,

Borja.

Re: RichText variable, how to get RTF text?
Wolfgang Uhr - Thu Mar 26 04:55:44 EDT 2015

Borja López - Thu Mar 26 04:16:00 EDT 2015

This way I would get the RTF of the whole object.

However, what I want to get is the RTF of the non-OLE parts (the ELSE side in the code), together with a replacing markup for the OLE parts (the IF side), so your solution is not valid for my problem.

Regards,

Borja.

There is an example in the manual. Do you mean this?

void checkOLEcount(Object o, string attributeName) 
{ 
    int n = oleCount(o.attributeName) 
    RichText rtf 
    string s = richTextWithOle o.attributeName 
    int j = 0 
    for rtf in s do  
    { 
        if (rtf.isOle)   
        { 
           j++     
        }    
    }          
    if (j != n) 
    { 
        print "ERROR: oleCount gives " n " and for rtf in string gives " j "\n"     
    } else { 
        print "OK: they both give " n "\n" 
    }         
} 
Object o = current 
checkOLEcount(o, "Object Text") 

 

Re: RichText variable, how to get RTF text?
Borja López - Thu Mar 26 05:08:51 EDT 2015

Wolfgang Uhr - Thu Mar 26 04:55:44 EDT 2015

There is an example in the manual. Do you mean this?

void checkOLEcount(Object o, string attributeName) 
{ 
    int n = oleCount(o.attributeName) 
    RichText rtf 
    string s = richTextWithOle o.attributeName 
    int j = 0 
    for rtf in s do  
    { 
        if (rtf.isOle)   
        { 
           j++     
        }    
    }          
    if (j != n) 
    { 
        print "ERROR: oleCount gives " n " and for rtf in string gives " j "\n"     
    } else { 
        print "OK: they both give " n "\n" 
    }         
} 
Object o = current 
checkOLEcount(o, "Object Text") 

 

Yes, it's going that way, but what I really need is to take the RTF text for the "non-ole" parts

 

if (rtf.isOle) { 
           j++     
           // OLE => That's perfect
}  else {

    // NO OLE => How to take the formatted text??
    
}

 

Re: RichText variable, how to get RTF text?
Wolfgang Uhr - Thu Mar 26 07:31:34 EDT 2015

Borja López - Thu Mar 26 05:08:51 EDT 2015

Yes, it's going that way, but what I really need is to take the RTF text for the "non-ole" parts

 

if (rtf.isOle) { 
           j++     
           // OLE => That's perfect
}  else {

    // NO OLE => How to take the formatted text??
    
}

 

    for rtf in sTest do {
  if (rtf.isOle) {
   print "OLE";
  } else {
   if (rtf.bold) { print "BOLD>" };
   print rtf.text;
   if (rtf.bold) { print "<BOLD" };
  }
 }

? 

Re: RichText variable, how to get RTF text?
O.Wilkop - Thu Mar 26 07:49:58 EDT 2015

Borja López - Thu Mar 26 05:08:51 EDT 2015

Yes, it's going that way, but what I really need is to take the RTF text for the "non-ole" parts

 

if (rtf.isOle) { 
           j++     
           // OLE => That's perfect
}  else {

    // NO OLE => How to take the formatted text??
    
}

 

there seems to be no way to get the rtf text of a RichText variable. You can either check and add every rtf tag manually (so check for bold, italic, etc.) and see if you are able to get all possible combinations with that, or you try something else:

 

string s = richTextWithOle(o."Object Text");
RichText rtf;

string containedOle = "";
for rtf in s do{
    if(rtf.isOle){
        EmbeddedOleObject ole = rtf.getEmbeddedOle;
        containedOle = oleRtf(ole);
    }
}

if(containedOle != ""){
    //replace the OLE rtf string inside string s with your new OLE rtf
}

 

Basically I'd suggest you look for OLE objects in your rtf string, save their rtf representation and replace it with your new rtf string instead. Remember that there might be more than one OLE in a string, so you'd need to check for that. Replacing the rtf part afterwards would probably work with a combination of findRichText() and replaceRichText().

Re: RichText variable, how to get RTF text?
Mike.Scharnow - Fri Jun 15 10:34:20 EDT 2018

Hello Borja,

sorry for pulling such an old thread.

Have you been able to solve your problem? Currently, I'm having exact the same assignment...

 

Thanks & Regards

Mike